//泛型接口

// 第一种
interface iMutiple {
    <T>(arr: T[], init: number): number;
}

// 函数表达式类型
const mutipless: iMutiple = function (arr,) {
    return arr.reduce((pre, cur: any) => pre + cur, 0)
};

console.log(mutipless<number>([1, 2, 3], 0));
console.log(mutipless(["1", "2", "3"], 0));


// 箭头函数类型
const mutiples: iMutiple = (arr, init) => {
    return arr.reduce((pre, next: any) => pre + next, init);
};
console.log(mutiples([1, 2, 3], 0));
console.log(mutiples(["1", "2", "3"], 0));


// // 第二种
interface iMutipleS<T> {
    (arr: T[], init: number): number;
}

// 箭头函数类型  使用第二种 必须提供参数
const mutip: iMutipleS<string> = (arr, init = 0) => {
    return arr.reduce((pre, next: any) => pre + next, init);
};
// console.log(mutip([1, 2, 3], 0)); //报错
console.log(mutip(["1", "2", "3"], 0));

interface zzzks<T> {
    (a: number, b: T): T;
}

const zkssssss: zzzks<string> = (a, b) => {
    return a + b;
};

console.log(zkssssss(1, "2"));


interface Box<T> {
    content: T;
}

interface Apple {
    name: string;
}

type AppleBox = Box<Apple>;

let ass: AppleBox = {
    content: {name: "苹果"},
};

type orNUll<T> = null | T;

type oneOrMany<T> = T | T[];
type oneOrManyOrNull<T> = orNUll<oneOrMany<T>>;

const zzwks1: oneOrManyOrNull<string> = []
const zzwks2: oneOrManyOrNull<number> = 55
const zzwks3: oneOrManyOrNull<string> = 'sad555'